#!/usr/bin/perl
#
# Coded by Loni - loni@securityforest.com
# Created:  19/11/2004
# Updated:  26/12/2004 (no changing directory into ExploitTree)
#
# Search Utility for the ExploitTree CVS Repository Tree from SecurityForest.com
# This is a really lame script (only uses bids.txt), but the Real Search Engine is on its way...

$ver = "v0.2";
$name = "xsearch.pl";

$winexe = "no"; #Only applicable when distributed as an exe with binary unix utilities
if ($winexe eq "yes") { 
	$name = "xsearch.exe"; 
	$dir = $0; $dir =~ s/\\$name//;
	$ENV{'PATH'} = "$dir\\bin;$ENV{'PATH'}";
}

&master();

sub master {
	print "\nXsearch engine for ExploitTree $ver\n----------------------------------------\n\n";
	print "1\) Search via BID\n"; 
	print "2\) Search via exploit name\n"; 
	print "3\) Search via keyword\n";
	print "+---------------------------------------\nq\) Quit\n\n> ";
	chomp($choice = <STDIN>);
	if ($choice == 1) { &searchbid(); &master();}
	if ($choice == 2) { &searchname(); &master();}
	if ($choice == 3) { &searchkey(); &master();}
	elsif ($ch_list == "q") { print "Quitting...\n"; exit(1); }    
}

sub searchbid {
	print "BID> "; chomp($choicetext = <STDIN>);
	#system("cd ExploitTree && grep :$choicetext: bids.txt && cd ..");
	system("grep :$choicetext: bids.txt");
}

sub searchname {
	print "Exploit Name> "; chomp($choicetext = <STDIN>);
	#system("cd ExploitTree && grep :$choicetext bids.txt && cd ..");
	system("grep :$choicetext bids.txt");
}

sub searchkey {
	print "KeyWord> "; chomp($choicetext = <STDIN>);
	#system("cd ExploitTree && grep $choicetext bids.txt && cd ..");
	system("grep $choicetext bids.txt");
}

#EOF

